package org.piaohao.util.string;

import java.util.Random;

/**
 *
 * @author piaohao
 */
public class StringUtil {

    public static String generateChinese() throws Exception {
        String str;
        int hightPos, lowPos; // 定义高低位
        Random random = new Random();
        hightPos = (176 + Math.abs(random.nextInt(39)));//获取高位值
        lowPos = (161 + Math.abs(random.nextInt(93)));//获取低位值
        byte[] b = new byte[2];
        b[0] = (new Integer(hightPos).byteValue());
        b[1] = (new Integer(lowPos).byteValue());
        str = new String(b, "GBk");//转成中文
        return str;
    }

    public static String generateChinese(int count) throws Exception {
        String str = "";
        for (int i = 0; i < count; i++) {
            str += generateChinese();
        }
        return str;
    }

    public static String generateChineseName() throws Exception {
        String firstName = ""
                + "赵钱孙李周吴郑王冯陈"
                + "诸卫蒋沈韩杨朱秦尤许"
                + "何吕施张孔曹严华金魏"
                + "陶姜戚谢邹喻柏水窦章"
                + "云苏潘葛奚范彭郎鲁韦"
                + "昌马苗凤花方俞任袁柳"
                + "酆鲍史唐费廉岑薛雷贺"
                + "倪汤滕殷罗毕郝邬安常"
                + "乐于时傅皮卡齐康伍余"
                + "元卜顾孟平黄和穆萧尹";
        String name = String.valueOf(firstName.charAt(new Random().nextInt(100)));
        int count = new Random().nextInt(2) + 1;
        for (int i = 0; i < count; i++) {
            name += generateChinese();
        }
        return name;
    }

    public static String generatePhone() {
        String phone = "1";
        for (int i = 0; i < 10; i++) {
            phone += new Random().nextInt(10);
        }
        return phone;
    }

    public static String generateNumber(int count) {
        String str = "";
        for (int i = 0; i < count; i++) {
            str += new Random().nextInt(10);
        }
        return str;
    }

    public static String generateEmail() {
        String email = "";
        for (int i = 0; i < 9; i++) {
            email += new Random().nextInt(10);
        }
        email += "@qq.com";
        return email;
    }

    public static String generatePlateNumber() {
        String number = "渝";
        char c = 'A';
        number += (char) (c + new Random().nextInt(26));
        for (int i = 0; i < 5; i++) {
            number += new Random().nextInt(10);
        }
        return number;
    }

    public static String generateVehModel() {
        String model = "渝";
        char c = 'A';
        model += (char) (c + new Random().nextInt(26));
        model += (char) (c + new Random().nextInt(26));
        model += (char) (c + new Random().nextInt(26));
        for (int i = 0; i < 5; i++) {
            model += new Random().nextInt(10);
        }
        return model;
    }

    public static void main(String[] args) throws Exception {
        System.out.println(StringUtil.generateChineseName());
        System.out.println(StringUtil.generatePlateNumber());
    }
}
